package com.hospital.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.util.DbUtil;

public class SelectServlet extends HttpServlet{
	//实现二级联动
    private static final long serialVersionUID = 1L;
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException{
        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String targetId = request.getParameter("deptidGet").toString();
        //System.out.println(targetId);
        // 获得请求中参数为id的值
        String xml_start = "<selects>";
        String xml_end = "</selects>";
        String xml = "";
        String sql_doctor = "select * from t_user_info where deptId = "+targetId;
		List<Map<String, Object>> list_doctor = DbUtil.find(sql_doctor);
		Map<String, Object> map_doctor = null;
		for (int i = 0; i < list_doctor.size(); i++) {
			map_doctor = (Map<String, Object>)list_doctor.get(i);
			xml += "<select><value>"+map_doctor.get("account")+"</value><text>"+map_doctor.get("account")+"</text></select>";
		}
        String last_xml = xml_start + xml + xml_end;
        response.getWriter().write(last_xml);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}

